import * as Common from './common';

(function (doc, win) {
    const docEl = doc.documentElement;
    const queryString = Common.getQueryString();

    const resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    const recalc = window.recalculate || function () {
        let clientWidth = docEl.clientWidth;
        if (!clientWidth || docEl.style.fontSize) {
            return;
        }
        if (queryString && queryString.width) clientWidth = parseInt(queryString.width);

        const fontSize = clientWidth / 1920;
        window.htmlFontSize = fontSize;
        docEl.style.fontSize = `${fontSize}px`;
    };
    if (!doc.addEventListener) {
        return;
    }
    win.addEventListener(resizeEvt, recalc, false);
    recalc();
})(document, window);